package com.taotao.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.taotao.common.service.RedisService;

@Controller
@RequestMapping("item/cache")
public class ItemCaCheController {
	@Autowired
	private RedisService redisService;
	//从配置文件中读取key缓存
    @Value("${REDIS_ITEM_KEY}")
    protected String REDIS_ITEM_KEY;
	@RequestMapping(value="{itemId}",method=RequestMethod.POST)
	public ResponseEntity<Void> deleteCaChe(
			@PathVariable(value = "itemId") Long itemId) {
		try {
			//删除缓存数据
			String key = REDIS_ITEM_KEY+itemId;
			this.redisService.del(key);
			return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//500
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
	}
}
